﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bingosoft.Modules.SecurityConsole.Organization;
using Bingosoft.Web.Utils;

namespace Bingosoft.WebApp.Modules.SecurityConsole.Organization
{
    public partial class AddOrganizationProcessUser : System.Web.UI.BasePage
    {
        private OrganizationService _service;
        private OrganizationService Service
        {
            get
            {
                return _service ?? (_service = ObjectHelper.GetObject<OrganizationService>());
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["Id"] != null && Request.QueryString["Name"] != null)
            {
                labUser.Text = Request.QueryString["Name"];
                RefreshRoleUser();
            }
        }

        private void RefreshRoleUser()
        {
            SmartSqlDataSource2.SelectCommand = "organization.role.user-members";
            SmartSqlDataSource2.SelectParameters.Add("Id",Request.QueryString["Id"]);
            gvRoleUser.DataBind();
        }

        protected void btnAddUser_Click(object sender, EventArgs e)
        {
            Service.AddRoleUsers(Request.QueryString["Id"],ReturnIds.Value.Split(','));
            RefreshRoleUser(); 
        }

        protected void RoleUserDelete(object sender, EventArgs e)
        {
            ImageButton img = sender as ImageButton;
            string wfRoleId = img.Attributes["_KeyId"];
            string userId = img.Attributes["_UserId"];
            Service.RemoveRoleUser(wfRoleId, userId);
            RefreshRoleUser();
        }

    }
}